<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <div class="seach-box">
        <div class="select-box-content">
          <div class="select-box-content-name">备件名称：</div>
          <el-input
            v-model="sparePartName"
            clearable
            placeholder="请输入备件名称"
            @change="queryPageList()"
          />
        </div>
        <div class="select-box-content">
          <div class="select-box-content-name">选择时间：</div>
          <el-date-picker
            v-model="generationTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            clearable
            @change="queryPageList()"
          />
        </div>
      </div>
    </template>
    <template v-slot:typenodeslot>
      <!-- <SelectButton :topitem-select-list="topitemSelectList" @topitemtype="topitemtype" /> -->
    </template>
    <template v-slot:content>
      <e-table
      rowKey="sparePartCode"
        :table-data="tableData"
        :table-columns="tableLabel"
        :page="currentPage"
        :size="pageSize"
        :total="totalSize"
        :loading="loading"
        @sizeChange="changePageSize"
        @pageChange="changeCurrentPage"
        @tableUpdatePlus="mixTableUpdatePlus"
      >
        <template slot="inCount">
          <div>{{ generationTime?'入库数量':'总入库数量' }}</div>
        </template>
        <template slot="outCount">
          <div>{{ generationTime?'出库数量':'总出库数量' }}</div>
        </template>
      </e-table>
    </template>
  </BaseMainSlot>
</template>

  <script>
import Pagination from "@/components/Pagination";
import sparePartDayReport from "@/api/spare-part-manage/spare-part-day-report";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import { mymixin } from "@/utils/mixin";
import SelectButton from "@/components/equipTypeSelectButton/selcetButton.vue";

export default {
  name: "sparePartReport",
  components: { Pagination, BaseMainSlot, SelectButton },
  mixins: [mymixin],
  data() {
    return {
      tableData: [],
      // 所搜条件：备件名称
      sparePartName: "",
      // 所搜条件：保养设备
      equipmentName: "",
      // 所搜条件：选择时间
      generationTime: "",
      startTime: "",
      endTime: "",
      tableLabel: [
        {
          label: "备件型号",
          param: "sparePartName",
          notSearch: true,
        },
        {
          label: "备件编号",
          param: "sparePartCode",
          show: true,
          notSearch: true,
        },
        {
          label: "备件类型",
          param: "sparePartTypeName",
          notSearch: true,
        },
        {
          label: "入库数量",
          param: "inCount",
          show: true,
          header: "inCount",
          notSearch: true,
        },
        {
          label: "出库数量",
          param: "outCount",
          header: "outCount",
          show: true,
          notSearch: true,
        },
        {
          label: "关联设备型号",
          param: "modelName",
          notSearch: true,
        },
        {
          label: "剩余数量",
          param: "leaveCount",
          show: true,
          notSearch: true,
        },
      ],
    };
  },
  watch: {},
  created() {
    var time = new Date();
    this.generationTime = this.$moment(time).format("YYYY-MM-DD");
    this.startTime = this.$moment().startOf("day").format("YYYY/MM/DD");
    this.endTime = this.$moment().format("YYYY/MM/DD");
    this.queryPageList();
  },
  mounted() {},
  methods: {
    queryPageList(e) {
      this.loading = false;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
      };
      let entity = {};
      if (this.sparePartName) {
        entity.sparePartName = this.sparePartName;
      }
      if (this.generationTime) {
        (entity.startDate = this.generationTime + " 00:00:00"),
          (entity.endDate = this.generationTime + " 23:59:59");
      }
      entity = { ...e };
      params.entity = entity;
      sparePartDayReport.queryPageDailyList(params).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          this.totalSize = data.total;
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    // changePageSize(pageSize) {
    //   if (this.topitemtypeId === "任务") {
    //     this.pageSize = pageSize;
    //   }
    //   if (this.topitemtypeId === "异常任务") {
    //     this.anPageSize = pageSize;
    //   }
    //   this.queryList();
    // },
    // changeCurrentPage(currentPage) {
    //   if (this.topitemtypeId === "任务") {
    //     this.currentPage = currentPage;
    //   }
    //   if (this.topitemtypeId === "异常任务") {
    //     this.anCurrentPage = currentPage;
    //   }
    //   this.queryList();
    // },
    // 修改
    edit(row) {
      if (row.taskId) {
        this.showAddEditDialog = true;
        this.editObject = JSON.parse(JSON.stringify(row));
      }
    },
  },
};
</script>

  <style lang="scss" scoped>
</style>
